<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>表格管理</title>
    <link rel="stylesheet" href="/static/css/layui.css">
</head>

<body>

<!-- 主体部分 -->
<div class="layui-card">
    <div class="layui-card-body">


        <div class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" id="ID" name="ID" placeholder="编号" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button id="btn_search" class="layui-btn layui-icon  layui-icon-search" data-type="search">查询
                    </button>
                </div>
                <div class="layui-inline">
                    <button id="btn_refresh" class="layui-btn layui-icon  layui-icon-refresh" data-type="search">重置
                    </button>
                </div>
            </div>

        </div>

        <table id="manage_table" lay-filter="manage_table"></table>
    </div>
</div>

<!-- 表格基本操作按钮 -->
<script type="text/html" id="table_operation">
    <a class="layui-btn layui-btn-xs" lay-event="score">查看抄袭版本</a>
</script>



<!-- javascript 脚本 -->
<script src="/static/layui.js"></script>
<script>
    layui.use(['layer', 'form', 'table','dropdown'], function () {
        var dropdown = layui.dropdown;
        var table = layui.table;
        var
            $ = layui.jquery,
            table = layui.table,
            form = layui.form,
            layer = layui.layer;

        var currentRow = {},
            currentOpt = "",
            loadUrl = "/homework/load",
            submitUrl = "/homework/submit",
            listUrl = "/homework/list1",
            layerIndex = 0;

        $(function () {
            // 查询按钮
            $("#btn_search").on("click", function () {
                table.reload('manage_table', {
                    where: {
                        ID: $("#ID").val()
                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            });
            $("#btn_refresh").on("click", function () {
                initTable();
            });
            initTable();
        });

        function initTable() {
            // 初始化列表(表格)
            table.render({
                elem: '#manage_table'
                , url: listUrl //数据接口
                , method: "GET"
                , toolbar: '#tableToolBar'
                , defaultToolbar: []
                ,limit: 10
                ,limits: [10,20,30,40,50]
                , cellMinWidth: 100
                , request: {
                    pageName: 'pageIndex',  // 页码的参数名称，默认：page
                    limitName: 'pageSize'   // 每页数据量的参数名，默认：limit
                }
                , page: {
                    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'],     // 自定义分页布局
                    curr: 1,      // 设置默认起始页1
                    groups: 10,   //只显示10个连续页码,就是说显示10个可见页其他的省略
                    first: false, // 不显示首页
                    last: false   // 不显示尾页
                }
                , cols: [
                    [ //表头
                        {field: 'ID', title: '作业编号', align: 'center', width: 100}
                        , {field: 'tid', title: '老师编号', align: 'center', width: 100}
                        , {field: 'title', title: '标题', align: 'center'}
                        , {field: 'h_content', title: '详细内容', align: 'center'}
                        , {field: 'issuedate', title: '发布日期', align: 'center'}
                        , {field: 'deadline', title: '截止日期', align: 'center'}
                        , {field: 'submit_limit', title: '提交次数限制', align: 'center'}
                        , {field: 'answer', title: '标准答案', align: 'center'}
                        , {
                        width: 160,
                        align: 'center',
                        title: '操作',
                        toolbar: '#table_operation',
                        fixed: 'right'
                    }
                    ]
                ],
                parseData: function (res) { //res 即为原始返回的数据
                    console.log(res)
                    return {
                        "code": res.code == 200 ? 0 : res.code, //解析接口状态
                        "msg": res.code == 200 ? "" : res.msg, //解析提示文本
                        "count": res.count, //解析数据长度
                        "data": res.data //解析数据列表
                    };
                }
            });

        // 绑定表格bar 按钮事件
        table.on('tool(manage_table)', function (obj) {
                console.log(obj)
                if (obj.event === 'score') {
                    currentRow = obj.data;
                    console.log(currentRow)
                    currentOpt = loadUrl;
                    layerIndex = layer.open({
                        title: currentRow.ID + "作业所有抄袭版本",
                        type: 1,
                        shadeClose: true,
                        offset: '2%',
                        area: ['80%', '95%'],
                        content:'<div style="margin: 10px;"><table id="templateTable"></table></div>',
                        success:function (res) {
                            console.log(res)
                            table.render({
                                elem: '#templateTable'
                                ,url: "/uploadhomework/list2"
                                ,where:{hnumber: currentRow.ID}
                                //, request: {
                                //    pageName: 'pageIndex',  // 页码的参数名称，默认：page
                                //    limitName: 'pageSize'   // 每页数据量的参数名，默认：limit
                                //}
                                // , page: {
                                //    layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'],     // 自定义分页布局
                                //    curr: 1,      // 设置默认起始页1s
                                //    groups: 10,   //只显示10个连续页码,就是说显示10个可见页其他的省略
                                //   first: false, // 不显示首页
                                //    last: false   // 不显示尾页
                                //}
                                // ,limits: [10,20,30,40,50]

                                , cols: [
                                    [ //表头
                                        //{field: 'ID', title: '编号', align: 'center', width: 100}
                                        {field: 'class_name', title: '班级', align: 'center', width: 100}
                                        , {field: 'version', title: '版本号', align: 'center', width: 150}
                                        , {field: 'plagiarized_students', title: '抄袭学生学号', align: 'center'}
                                    ]
                                ],
                            });

                        },

                        btn: ['返回'],
                        yes: function(index){
                            layer.close(index);
                        }
                    });

                }
            });
        }



    });
</script>

</body>

</html>
